package airport.client.widget.notfound;

import airport.client.Airport;
import airport.shared.beans.UserBean;
import airport.shared.service.AirportService;
import airport.shared.service.AirportServiceAsync;
import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;


/**
 * Created by Romain on 04/03/15.
 */
public class NotFoundWB extends Airport {

    public interface MyResources extends ClientBundle {
        public static final MyResources INSTANCE = GWT.create(MyResources.class);

        @Source("Stop.png")
        public ImageResource sansInterdit();
    }


    FlowPanel panel = new FlowPanel();
    FlowPanel panelRow = new FlowPanel();
    Label text = new Label("404 Page Not Found");
    Image stop = new Image(MyResources.INSTANCE.sansInterdit());

    public NotFoundWB() {

        initWidget(panelRow);
        checkLogin();

    }

    public void init() {
        panelRow.setStyleName("row-fluid");
        panel.setStyleName("panneau-info span6 offset4 secondary");
        panel.add(text);
        stop.setStyleName("aligner");
        panel.add(stop);
        panelRow.add(panel);
    }

    public void checkLogin() {
        final AirportServiceAsync connexionIface;
        connexionIface = GWT.create(AirportService.class);

        connexionIface.checkLogin(new AsyncCallback<UserBean>() {

            @Override
            public void onFailure(Throwable caught) {
                infoDanger(caught.toString());
            }

            @Override
            public void onSuccess(UserBean result) {
                if (result != null) {
                    init();
                    labelTitre.getElement().setInnerHTML("Bienvenue " + result.getPrenom() + " " + result.getNom());
                } else {
                    initbouton(false);
                    init();
                }
            }
        });
    }

}